package logic

import (
	"context"
	"errors"
	"shop_srv/models"

	"shop_srv/internal/svc"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateActivityLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateActivityLogic {
	return &CreateActivityLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateActivityLogic) CreateActivity(in *shop.CreateActivityRequest) (*shop.CreateActivityResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var a models.Activity

	a.GoodsID = int(in.GoodsId)
	a.ActivityPrice = float64(in.ActivityPrice)
	a.Progress = in.Progress
	a.Countdown = in.Countdown
	if err = a.AddActivity(); err != nil {
		logx.Error("活动创建失败")
		return nil, errors.New("活动创建失败")
	}

	return &shop.CreateActivityResponse{
		ActivityId: int64(a.ID),
	}, nil
}
